package senior.ioExer2;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * baidu RandomAcessFile的用法，给出案例
 *
 * @author shkstart
 * @creat 2022-04-19:49
 */
public class Exer9 {
    public static void main(String[] args) {
        String filePath = "D:/.temp/hello.txt";
        RandomAccessFile raf = null;
        File file = null;
        try {
            file = new File(filePath);
            // 以读写的方式打开一个RandomAccessFile对象
            raf = new RandomAccessFile(file, "rw");
            //将记录指针移动到该文件的最后
            raf.seek(raf.length());
            //向文件末尾追加内容
            raf.writeChars("这是追加内容。。");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (raf != null) {
                    raf.close();
                    System.out.println("操作成功");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}

